﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using COM.Rights.Model;
using COM.Rights.BLL;
using System.Data;
using System.Text;

public partial class Pages_BdNews_Edit : ZMPageEdit<BdNews, BdNewsInfo>
{ 
	#region 重写方法

    protected override void OnLoading()
    {
        base.OnLoading();

        if (!IsPostBack)
        {
            BindHostName();
        }
    }

    protected override void OnAchieve()
    {
        StringBuilder sb = new StringBuilder();
        foreach (ListItem item in HostNames.Items)
        {
            if (item.Selected) {
                sb.Append(";");
                sb.Append(item.Value);
            }
        }
        if (!string.IsNullOrEmpty(sb.ToString()) && sb.ToString().IndexOf(";") == 0)
        {
            Model.HostName = sb.ToString().Substring(1, sb.ToString().Length - 1);
        }
        //Model. = ZASession.Account;
        base.OnAchieve();
    }


    protected  void BindHostName()
    {
        

        PermUserWeb _PermUserWeb = new PermUserWeb();
        List<DBParameter> _listDBParameter = new List<DBParameter>();
        _listDBParameter.Add(new DBParameter("@TranType", "hostname"));
        _listDBParameter.Add(new DBParameter("@UID", ZASession.Account));

        IDataReader sdr = _PermUserWeb.ExecuteReader("[dbo].[mdlist_sel]", _listDBParameter, System.Data.CommandType.StoredProcedure);
        DataTable dt = new DataTable();
        dt.Load(sdr);

        ZABinder.FillList(string.Empty, HostNames, false, dt);
    }

    

    protected override void OnBinding()
    {
        base.OnBinding();
        if (!IsNewModel)
        {
            string[] arr = this.Model.HostName.Split(';');
            if (arr != null && arr.Length > 0)
            {

                foreach (ListItem item in HostNames.Items)
                {
                    foreach (string host in arr)
                    {
                        if (string.Compare(host, item.Value, false) == 0)
                        {
                            item.Selected = true;
                            break;
                        }
                    }
                }
            }
        }

       
    }


    #endregion 	重写方法
}